Skip to content

Implement Roc codegen backend and runner support (#1964) - #12465

Merged
dezren39 merged 2 commits into
mainfrom
queue/12882-1964-roc-script-support
Nov 22, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/12882-1964-roc-script-support

Conversation

@dezren39

@dezren39 dezren39 commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Closes #1964. Implements Roc codegen backend and runner support mirroring the Python implementation.


Run Proof on this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 22, 2026 07:21
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5e7648ee-4501-4c52-a854-43fd2b676434
Commits

Reviewing files that changed from the base of the PR and between 0e82202 and 2a39796.

Files selected for processing: 20

  • pkgs/mcpx/docs/configuration.md
  • pkgs/mcpx/docs/runtimes.md
  • pkgs/mcpx/internal/api/ops_exec.go
  • pkgs/mcpx/internal/api/ops_exec_schema_test.go
  • pkgs/mcpx/internal/cli/commands.go
  • pkgs/mcpx/internal/cli/flagindex_generated.go
  • pkgs/mcpx/internal/cli/scripts.go
  • pkgs/mcpx/internal/codegen/language.go
  • pkgs/mcpx/internal/codegen/language_test.go
  • pkgs/mcpx/internal/codegen/roc.go
  • pkgs/mcpx/internal/codegen/roc_test.go
  • pkgs/mcpx/internal/daemon/consumer.go
  • pkgs/mcpx/internal/execsvc/execsvc.go
  • pkgs/mcpx/internal/runner/dispatch.go
  • pkgs/mcpx/internal/runner/language.go
  • pkgs/mcpx/internal/runner/roc_test.go
  • pkgs/mcpx/internal/runner/runner.go
  • pkgs/mcpx/internal/scriptresolve/scriptresolve.go
  • pkgs/mcpx/internal/settings/registry.go
  • pkgs/mcpx/plugin/core/ops.gen.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T07:26:53.163668Z c9443d9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…script-support

# Conflicts:
#	pkgs/mcpx/internal/cli/commands.go
#	pkgs/mcpx/internal/cli/flagindex_generated.go
#	pkgs/mcpx/plugin/core/ops.gen.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c9443d90d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +43 to +44
fmt.Fprintf(&b, " payload = { server: %s, tool: %s, args }\n", rocString(fn.server), rocString(fn.tool))
b.WriteString(" body = Json.to_str_try(payload) ? |_err| TransportError(\"mcpx request encoding failed\")\n call!(body)\n}\n\n")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore original argument keys before JSON encoding

For schemas containing properties such as a-b, if, or colliding names like a-b and a_b, rocInputFields renames the fields, but this payload serializes the renamed record directly. The daemon consequently receives keys such as a_b, if_, and a_b_2 instead of the schema's original keys, causing required arguments to be missing or values to reach the wrong property. Preserve the original-to-generated field mapping and use the original keys when constructing the JSON request.

Useful? React with 👍 / 👎.

case "boolean":
typ = "Bool"
}
fields = append(fields, uniqueRocIdent(rocIdent(k, false), usedNames)+" : "+typ)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve omission semantics for optional arguments

When a tool schema has optional properties, every property is nevertheless emitted as a mandatory record field, and the complete record is serialized into the request. A caller therefore cannot omit an optional argument to use the server's default or leave a setting unchanged; supplying an empty string, zero, or false is not equivalent to omission. Read the schema's required set and provide an argument representation and encoder that can leave optional keys out of the payload.

Useful? React with 👍 / 👎.

Comment on lines +100 to +101
if len(fields) == 0 {
return []string{"_unit : {}"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Encode an empty object for tools without arguments

For a tool whose input schema has no properties, the generated signature requires an artificial _unit field. Because the wrapper serializes args unchanged, the request contains {"_unit":{}} rather than {}. A no-argument tool with additionalProperties:false will reject that request. Keep any unit value needed by the Roc call interface separate from the wire arguments and encode an empty object for this case.

Useful? React with 👍 / 👎.

Comment on lines +182 to +184
bin, err := exec.LookPath("roc")
if err != nil {
return nil, errors.New("runner: roc binary not found on PATH for a Roc script")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Defer Roc lookup when the devshell supplies the compiler

When script.devshell=flake:<ref> provides Roc but the host has no roc executable, this lookup rejects .roc files and explicitly selected Roc snippets before execution reaches the devshell wrapper in runDispatched. This prevents using the configured development environment to supply the compiler, despite the devshell-owned PATH behavior documented in docs/runtimes.md:59. Allow the unresolved roc invocation through for flake environments, as the JavaScript dispatch path already does.

Useful? React with 👍 / 👎.

b.WriteString("call! = |body| {\n")
b.WriteString(" endpoint = match Env.var_str!(\"MCPX_ENDPOINT\") {\n Ok(value) => value\n Err(_) => default_endpoint\n }\n")
b.WriteString(" session = match Env.var_str!(\"MCPX_SESSION\") {\n Ok(value) => value\n Err(_) => default_session\n }\n")
b.WriteString(" request = Request.from_method(Method.POST)\n .with_uri(Str.concat(endpoint, \"/v1/call\"))\n .with_body(Str.to_utf8(body))\n .add_header(\"Content-Type\", \"application/json\")\n .add_header(\"x-mcpx-session\", session)\n .add_header(\"x-mcpx-call\", session)\n")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Authenticate requests with the supplied daemon bearer token

When transport.bearerToken is configured, every generated Roc tool call receives HTTP 401 because the request never includes an Authorization header. The exec service already supplies MCPX_TRANSPORT_BEARER_TOKEN in scriptEnv, and daemon/bearer.go's requireBearer enforces it on every HTTP route, including /v1/call. Read that environment variable and conditionally send Authorization: Bearer <token> so Roc scripts can use authenticated daemons.

Useful? React with 👍 / 👎.

b.WriteString("call! = |body| {\n")
b.WriteString(" endpoint = match Env.var_str!(\"MCPX_ENDPOINT\") {\n Ok(value) => value\n Err(_) => default_endpoint\n }\n")
b.WriteString(" session = match Env.var_str!(\"MCPX_SESSION\") {\n Ok(value) => value\n Err(_) => default_session\n }\n")
b.WriteString(" request = Request.from_method(Method.POST)\n .with_uri(Str.concat(endpoint, \"/v1/call\"))\n .with_body(Str.to_utf8(body))\n .add_header(\"Content-Type\", \"application/json\")\n .add_header(\"x-mcpx-session\", session)\n .add_header(\"x-mcpx-call\", session)\n")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Forward the run ID to preserve dry-run interception

For a Roc execution requested with dryRun:true, these requests omit X-Mcpx-Run even though the exec service supplies MCPX_RUN. In daemon/server.go, handleCall obtains the run identity exclusively from that header, and dryRunResult declines interception when the identity is empty. Consequently, Roc tool calls execute against real servers during a purported dry run, including calls with destructive side effects. Forward the run ID on every generated request so the daemon can recognize the dry-run registration.

Useful? React with 👍 / 👎.

b.WriteString("call! = |body| {\n")
b.WriteString(" endpoint = match Env.var_str!(\"MCPX_ENDPOINT\") {\n Ok(value) => value\n Err(_) => default_endpoint\n }\n")
b.WriteString(" session = match Env.var_str!(\"MCPX_SESSION\") {\n Ok(value) => value\n Err(_) => default_session\n }\n")
b.WriteString(" request = Request.from_method(Method.POST)\n .with_uri(Str.concat(endpoint, \"/v1/call\"))\n .with_body(Str.to_utf8(body))\n .add_header(\"Content-Type\", \"application/json\")\n .add_header(\"x-mcpx-session\", session)\n .add_header(\"x-mcpx-call\", session)\n")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Authenticate requests with the supplied daemon bearer token

When transport.bearerToken is configured, every generated Roc tool call receives HTTP 401 because the request never includes an Authorization header. The exec service already supplies MCPX_TRANSPORT_BEARER_TOKEN in scriptEnv, and daemon/bearer.go's requireBearer enforces it on every HTTP route. Read that environment variable and attach the bearer token to generated requests.

Useful? React with 👍 / 👎.

b.WriteString("call! = |body| {\n")
b.WriteString(" endpoint = match Env.var_str!(\"MCPX_ENDPOINT\") {\n Ok(value) => value\n Err(_) => default_endpoint\n }\n")
b.WriteString(" session = match Env.var_str!(\"MCPX_SESSION\") {\n Ok(value) => value\n Err(_) => default_session\n }\n")
b.WriteString(" request = Request.from_method(Method.POST)\n .with_uri(Str.concat(endpoint, \"/v1/call\"))\n .with_body(Str.to_utf8(body))\n .add_header(\"Content-Type\", \"application/json\")\n .add_header(\"x-mcpx-session\", session)\n .add_header(\"x-mcpx-call\", session)\n")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Forward the run ID so dry-run calls remain intercepted

When a Roc execution is requested with dryRun:true, the generated requests omit X-Mcpx-Run even though the exec service supplies MCPX_RUN. In daemon/server.go, handleCall obtains the run identity exclusively from that header, and dryRunResult declines interception when the identity is empty. Consequently, Roc tool calls execute against real servers during a purported dry run, including calls with destructive side effects. Forward the run ID on every generated request so the daemon can recognize the dry-run registration.

Useful? React with 👍 / 👎.

b.WriteString(" session = match Env.var_str!(\"MCPX_SESSION\") {\n Ok(value) => value\n Err(_) => default_session\n }\n")
b.WriteString(" request = Request.from_method(Method.POST)\n .with_uri(Str.concat(endpoint, \"/v1/call\"))\n .with_body(Str.to_utf8(body))\n .add_header(\"Content-Type\", \"application/json\")\n .add_header(\"x-mcpx-session\", session)\n .add_header(\"x-mcpx-call\", session)\n")
b.WriteString(" response = Http.send!(request, {}) ? |_err| TransportError(\"mcpx daemon request failed\")\n")
b.WriteString(" if Response.status(response) < 200 or Response.status(response) >= 300 {\n return Err(StatusError(Response.status(response)))\n }\n Ok(response)\n}\n\n")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Return an error for tool-level failure responses

When an MCP tool returns isError:true, the daemon preserves that envelope and responds with HTTP 200 (daemon/server.go:1282), so this status-only check returns Ok(response) for a failed tool invocation. Roc callers using the generated Try result for error handling will therefore continue down the success path after a tool failure. Decode the response envelope and convert tool-level failures into Err(ToolError) rather than treating every 2xx response as success; this also preserves the result-error contract in pkgs/mcpx/AGENTS.md.

AGENTS.md reference: pkgs/mcpx/AGENTS.md:L80-L80

Useful? React with 👍 / 👎.

@dezren39
dezren39 merged commit d5f8456 into main Nov 22, 2026
2 checks passed
@dezren39
dezren39 deleted the queue/12882-1964-roc-script-support branch November 22, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcpx: Roc as a script language, and whether mcpx should be a Roc platform

1 participant